﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using SandAbp.Framework.Core.SandAbp.Core;
using SandAbp.Openiddict.Verifications;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;

namespace SandAbp.Openiddict.Verification
{
    [RemoteService(Name = "Verification")]
    [ControllerName("Verification")]
    [Route("api/verification")]
    public  class VerificationController: OpeniddictController
    {
        private readonly IConfiguration _config;
        private readonly IVerificationAppService _verificationAppService;

        public VerificationController(IConfiguration config, IVerificationAppService verificationAppService)
        {
            this._config = config;
            this._verificationAppService = verificationAppService;
        }

        [HttpGet]
        [Route("verification-code")]
        public VerifyCode GetVerificationCode()
        {
            var veryCode = _verificationAppService.GetVerificationCode();
            //验证码统一转成小写MD5
            HttpContext.Response.Cookies.Append("verycode", Utils.Md5(veryCode.Code.ToLower()), new CookieOptions()
            {
                Expires = DateTime.Now.AddMinutes(5),
                SameSite = SameSiteMode.None,
                IsEssential = true
            });
            // return File(veryCode.Image, @"image/jpeg");
            return veryCode;
        }


       
    }
}
